package com.itheima.web.controller;

import com.itheima.web.manager.UserManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

    @Autowired
    UserManager userManager;

    //用户列表
    @GetMapping("/manage/users")
    public ResponseEntity findByPage(
            @RequestParam(value = "page",defaultValue = "1")Integer pageNum,
            @RequestParam(value = "pagesize",defaultValue = "10")Integer pageSize){
        return userManager.findByPage(pageNum,pageSize);
    }

    //用户详情
    @GetMapping("/manage/users/{userId}")
    public ResponseEntity findById(@PathVariable Long userId){
        return userManager.findById(userId);
    }

    //动态列表
    @GetMapping("/manage/messages")
    public ResponseEntity findMovementByPage(
            @RequestParam(value = "page",defaultValue = "1",required = false) Integer pageNum,
            @RequestParam(value = "pagesize",defaultValue = "10",required = false) Integer pageSize,
            @RequestParam(value = "uid",required = false) Long userId,
            @RequestParam(value = "state",required = false) Integer state){
        //1.接受4个参数

        //2.调用manager完成查询操作
        return userManager.findMovementByPage(pageNum,pageSize,userId,state);
    }

    //动态详情
    @GetMapping("/manage/messages/{publishId}")
    public ResponseEntity findMovementById(@PathVariable String publishId){
        return userManager.findMovementById(publishId);
    }

    //评论列表
    @GetMapping("/manage/messages/comments")
    public ResponseEntity findMovementComemntByPage(
            @RequestParam(value = "page",defaultValue = "1",required = false) Integer pageNum,
            @RequestParam(value = "pagesize",defaultValue = "10",required = false) Integer pageSize,
            @RequestParam(value = "messageID") String publishId){
        return userManager.findMovementComemntByPage(pageNum,pageSize,publishId);
    }
}
